#include "CRangedEnemy.h"

CRangedEnemy::CRangedEnemy()
{
	SetAlive(true);
	SetPassive(true);;
	SetDistanceToPlayer(VIN_Vector2D(0.0f, 0.0f));
	SetHP(90);
	SetPower(20);

	SetType(OBJ_ENEMY);
}

CRangedEnemy::~CRangedEnemy()
{

}

void CRangedEnemy::Attack()
{
	// TODO Start Shooting animation
	// If the animation completes substract from player's health by GetPower()
	// The attack must have a cooldown of at least 2 seconds
	// Play Shooting sound

}

void CRangedEnemy::HurtMe()
{ 
	SetHP(GetHP() - ( RandInt(20, 30) + (CHubState::GetInstance()->GetPlayer()->GetCombat() * 4)));
	if(GetHP() <= 0)
	{
		// TODO: Kill the enemy and increase the player's money by a random amount
		// Play enemy death sound
	}
}

void CRangedEnemy::Update( float fElapsedTime)
{
	// TODO Stay within a good range of the player, walking towards or away him as need be.
	// m_vDistanceToPlayer.m_fX = GetPosX() - CHubState::GetInstance()->GetPlayer()->GetPosX();
	// m_vDistanceToPlayer.m_fY = GetPosY() - CHubState::GetInstance()->GetPlayer()->GetPosY();

	SetDistanceToPlayer(VIN_Vector2D(GetPosX() - CHubState::GetInstance()->GetPlayer()->GetPosX(), GetPosY() - CHubState::GetInstance()->GetPlayer()->GetPosY()));


	if(GetDistanceToPlayer().LengthOfVector(GetDistanceToPlayer())  < 200.0f)
	{
		SetVelX(0.0f);
		SetVelY(0.0f);

		Attack();
	}
	else
	{
		if(GetPosX() > CHubState::GetInstance()->GetPlayer()->GetPosX())
		{
			SetVelX(-100.0f);
		}
		else
		{
			SetVelX(100.0f);

		}
		if(GetPosY() > CHubState::GetInstance()->GetPlayer()->GetPosY())
		{
			SetVelY(-20.0f);
		}
		else
		{
			SetVelY(20.0f);
		}
	}
	SetPosX(GetPosX() + (GetVelX() * fElapsedTime));
	SetPosY(GetPosY() + (GetVelY() * fElapsedTime));
}

void CRangedEnemy::Render()
{

}